import { Controller, Get, Post, Body, Patch, Param, Delete, Query, UseFilters, UseGuards } from '@nestjs/common';
import { TagService } from './tag.service';
import { CreateTagDto } from './dto/create-tag.dto';
import { UpdateTagDto } from './dto/update-tag.dto';
import { GetTagDto } from './dto/get-tag.dto';
import { TypeormFilter } from 'src/common/filters/typeorm.filter';
import { JwtGuard } from 'src/common/guards/jwt.guard';
import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { TagResultVo } from './vo/tag.result.vo';

@Controller('tag')
@ApiTags('标签')
@UseFilters(new TypeormFilter())
export class TagController {
  constructor(private readonly tagService: TagService) {}

  @Post()
  @ApiOperation({summary:'新增标签'})
  @ApiResponse({type:Number})
  @ApiBearerAuth()
  @UseGuards(JwtGuard)
  create(@Body() createTagDto: CreateTagDto) {
    return this.tagService.create(createTagDto)
  }

  @Get()
  @ApiOperation({summary:'标签列表'})
  @ApiResponse({type:TagResultVo})
  @ApiBearerAuth()
  @UseGuards(JwtGuard)
  findAll(@Query() query:GetTagDto) {
    return this.tagService.findAll(query,true);
  }

  @Get('user')
  @ApiOperation({summary:'标签列表（博客端）'})
  @ApiResponse({type:TagResultVo})
  findAllUser(@Query() query:GetTagDto) {
    return this.tagService.findAll(query,false);
  }

  @Get(':id')
  @ApiOperation({summary:'标签详情'})
  @ApiResponse({type:TagResultVo})
  @ApiBearerAuth()
  @UseGuards(JwtGuard)
  findOne(@Param('id') id: string) {
    return this.tagService.findOne(+id,true);
  }

  @Get('user/:id')
  @ApiOperation({summary:'标签详情（博客端）'})
  @ApiResponse({type:TagResultVo})
  findOneUser(@Param('id') id: string) {
    return this.tagService.findOne(+id,false);
  }

  @Patch(':id')
  @ApiOperation({summary:'标签修改'})
  @ApiResponse({type:null})
  @ApiBearerAuth()
  @UseGuards(JwtGuard)
  update(@Param('id') id: string, @Body() updateTagDto: UpdateTagDto) {
    return this.tagService.update(+id, updateTagDto);
  }

  @Delete(':id')
  @ApiOperation({summary:'标签删除'})
  @ApiResponse({type:null})
  @ApiBearerAuth()
  @UseGuards(JwtGuard)
  remove(@Param('id') id: string) {
    return this.tagService.remove(+id);
  }
}
